def is_clap_number(n):
    """判断一个数字是否需要拍手"""
    # 检查是否是7的倍数
    if n % 7 == 0:
        return True
    
    # 检查数字中是否包含7
    temp = n
    while temp > 0:
        if temp % 10 == 7:
            return True
        temp = temp // 10
    
    return False

def play_seven_game(limit=100):
    """玩逢七拍手游戏，输出需要拍手的数字"""
    print("逢七拍手游戏开始！")
    print("=" * 30)
    
    clap_numbers = []
    
    for i in range(1, limit + 1):
        if is_clap_number(i):
            clap_numbers.append(i)
            print(f"数字 {i}: 拍手！👏")
        else:
            print(f"数字 {i}: {i}")
    
    print("=" * 30)
    print(f"游戏结束！1到{limit}之间共有 {len(clap_numbers)} 个需要拍手的数字。")
    print(f"需要拍手的数字是：{clap_numbers}")
    
    return clap_numbers

def analyze_clap_pattern(clap_numbers):
    """分析拍手数字的分布规律"""
    print("\n=== 拍手数字分析 ===")
    
    # 按位数分析
    digit_analysis = {}
    for num in clap_numbers:
        digits = str(num)
        for digit in digits:
            digit_analysis[digit] = digit_analysis.get(digit, 0) + 1
    
    print("数字出现频率：")
    for digit, count in sorted(digit_analysis.items()):
        percentage = (count / len(clap_numbers)) * 100
        print(f"数字 {digit}: 出现 {count} 次 ({percentage:.1f}%)")
    
    # 按范围分析
    ranges = [(1, 10), (11, 20), (21, 30), (31, 40), (41, 50), (51, 60), (61, 70), (71, 80), (81, 90), (91, 100)]
    range_counts = []
    
    print("\n各区间拍手数字分布：")
    for start, end in ranges:
        count = sum(1 for num in clap_numbers if start <= num <= end)
        range_counts.append(count)
        print(f"{start}-{end}: {count} 个")
    
    # 计算7的倍数和包含7的数字比例
    multiple_of_7 = sum(1 for num in clap_numbers if num % 7 == 0)
    contains_7 = sum(1 for num in clap_numbers if '7' in str(num))
    both = multiple_of_7 + contains_7 - len(clap_numbers)  # 容斥原理
    
    print(f"\n7的倍数：{multiple_of_7} 个")
    print(f"包含7的数字：{contains_7} 个")
    print(f"既是7的倍数又包含7：{both} 个")

if __name__ == "__main__":
    # 玩游戏并获取结果
    result = play_seven_game(100)
    
    # 分析结果
    analyze_clap_pattern(result)
    
    # 提供一些有趣的统计信息
    print("\n=== 趣味统计 ===")
    print(f"平均每 {100 / len(result):.1f} 个数字就有一个需要拍手")
    
    # 找出连续拍手的最长序列
    max_streak = 0
    current_streak = 0
    prev_num = None
    
    for num in result:
        if prev_num is not None and num == prev_num + 1:
            current_streak += 1
            max_streak = max(max_streak, current_streak)
        else:
            current_streak = 1
        prev_num = num
    
    print(f"最长连续拍手序列：{max_streak} 个数字")
